package com.frank.pipeline.domain;

import com.frank.pipeline.codegen.entity.pipeline.tables.records.PipelineInfoRecord;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * @author jianweilin
 * @date 2017/11/7
 */
@Data
public class PipelineVo {
    private Integer id;

    @NotNull
    private Long pipelineNo;     // 管道编码

    @NotBlank
    private String manageSystem; // 管理系统

    @NotBlank
    private String runingInfo;  // 运行资料

    @NotBlank
    private String finishInfo;   // 竣工资料

    @NotBlank
    private String pipelineName;   // 管道名称

    @NotBlank
    private String pipelineType;   // 管道类型

    @NotNull
    private Double designPressure; // 设计压力

    @NotNull
    private Double runningPressure; // 运行压力

    @NotBlank
    private String material;       // 管材

    @NotBlank
    private String materialParams; // 管材参数

    @NotNull
    private Double pipelineLength; // 长度

    @NotNull
    private Double nominalDiameter;// 公称管径

    @NotNull
    private Double totalInvest;    // 总投资

    @NotNull
    private Long  operateDate;     // 投运日期

    @NotBlank
    private String pipelineStatus; // 状态

    @NotNull
    private Long checkDate;        // 全面检测日期

    @NotNull
    private Long nextCheckDate;    // 下次全面检测日期

    public static PipelineInfoRecord transferToPipelineInfo(PipelineVo pipelineVo){
        PipelineInfoRecord record = new PipelineInfoRecord();
        BeanUtils.copyProperties(pipelineVo,record);
        record.setDesignPressure(new BigDecimal(pipelineVo.getDesignPressure()));
        record.setRunningPressure(new BigDecimal(pipelineVo.getRunningPressure()));
        record.setName(pipelineVo.getPipelineName());
        record.setPipelineLength(new BigDecimal(pipelineVo.getPipelineLength()));
        record.setNominalDiameter(new BigDecimal(pipelineVo.getNominalDiameter()));
        record.setTotalInvest(new BigDecimal(pipelineVo.getTotalInvest()));
        record.setOperateDate(new Timestamp(pipelineVo.getOperateDate()));
        record.setCheckDate(new Timestamp(pipelineVo.getCheckDate()));
        record.setNextCheckDate(new Timestamp(pipelineVo.getNextCheckDate()));
        return record;
    }

    public static PipelineVo transferToPipelineVo(PipelineInfoRecord record){
        PipelineVo pipelineVo = new PipelineVo();
        BeanUtils.copyProperties(record,pipelineVo);
        pipelineVo.setTotalInvest(record.getTotalInvest().doubleValue());
        pipelineVo.setDesignPressure(record.getDesignPressure().doubleValue());
        pipelineVo.setRunningPressure(record.getRunningPressure().doubleValue());
        pipelineVo.setPipelineName(record.getName());
        pipelineVo.setPipelineLength(record.getPipelineLength().doubleValue());
        pipelineVo.setNominalDiameter(record.getNominalDiameter().doubleValue());
        pipelineVo.setOperateDate(record.getOperateDate().getTime());
        pipelineVo.setCheckDate(record.getCheckDate().getTime());
        pipelineVo.setNextCheckDate(record.getNextCheckDate().getTime());
        return pipelineVo;
    }
}
